//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Windows.Media;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    public abstract class PathElement : IOfficeXmlSerializable
    {
        public abstract PathSegment Segment { get; }

        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            ReadXmlCore(context);
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            WriteXmlCore(context);
        }

        #endregion

        internal abstract void ReadXmlCore(ReadContext context);

        internal abstract void WriteXmlCore(WriteContext context);

        internal static PathElement ReadPathElement(ReadContext c)
        {
            switch (c.ReaderLocalName)
            {
                case "moveTo":
                    var m = new Path2DMoveTo();
                    m.ReadXmlCore(c);
                    return m;
                case "lnTo":
                    var pp = new Path2DLineTo();
                    pp.ReadXmlCore(c);
                    return pp;
                case "close":
                    var cl = new Path2DClose();
                    cl.ReadXmlCore(c);
                    return cl;
                case "cubicBezTo":
                    var b = new Path2DCubicBezierTo();
                    b.ReadXmlCore(c);
                    return b;
                    case Path2DArcTo.xmlName:
                    var a = new Path2DArcTo();
                    a.ReadXmlCore(c);
                    return a;
                    case Path2DQuadBezierTo.xmlName:
                    Path2DQuadBezierTo p = new Path2DQuadBezierTo();
                    p.ReadXmlCore(c);
                    return p;
                default:
                    return null;
            }
        }
    }
}